package cn.dhnep.demo.service.impl;

import cn.dhnep.demo.mapper.AccountMapper;
import cn.dhnep.demo.pojo.Account;
import cn.dhnep.demo.pojo.vo.RespPageBean;
import cn.dhnep.demo.service.AccountService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author dhn
 * @since 2021-08-31
 */
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {

    @Override
    public RespPageBean pageQueryAccount(Integer current, Integer size, Integer type, String userName) {
        QueryWrapper<Account> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(type)) wrapper.eq("account_typeid", type);
        if (!StringUtils.isEmpty(userName)) wrapper.like("account_name", userName);
        Page<Account> page = new Page<>(current, size);
        baseMapper.selectPage(page, wrapper);
        return new RespPageBean(0, page.getTotal(), page.getRecords());
    }
}
